package com.gitee.wsl.compose.modifier

import androidx.compose.animation.animateContentSize
import androidx.compose.animation.core.FiniteAnimationSpec
import androidx.compose.animation.core.spring
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.IntSize


interface ModifierAnimateScope: ModifierScope {

    /**
     * fun showAnim() {
     *     var size by remember { mutableStateOf(Size(100F, 100F)) }
     *     Column(
     *         Modifier
     *             .fillMaxWidth()
     *             .fillMaxHeight(),
     *         Arrangement.Center,
     *         Alignment.CenterHorizontally
     *     ) {
     *         Box(
     *             Modifier
     *                 .animateContentSize()
     *         ) {
     *             Image(
     *                 painter = painterResource(id = R.drawable.icon_pdx),
     *                 contentDescription = null,
     *                 Modifier
     *                     .animateContentSize()
     *                     .size(size = size.height.dp)
     *             )
     *         }
     *         Spacer(Modifier.height(10.dp))
     *         Button(
     *             onClick = {
     *                 size = if (size.height == 100F) {
     *                     Size(250F, 250F)
     *                 } else {
     *                     Size(100F, 100F)
     *                 }
     *             }
     *         ) {
     *             Text(if (size.height == 100F) "收缩" else "展开")
     *         }
     *     }
     * }
     */
    fun  animateContentSize(
       animationSpec: FiniteAnimationSpec<IntSize> = spring(),
       finishedListener: ((initialValue: IntSize, targetValue: IntSize) -> Unit)? = null
    ){
       modifier = modifier.animateContentSize(animationSpec, finishedListener)
   }
}

class ModifierAnimateScopeImp(override var modifier: Modifier): ModifierAnimateScope

fun Modifier.animate(block: ModifierAnimateScope.()->Unit) = ModifierAnimateScopeImp(this).apply(block).modifier